import React, { Component } from 'react';
import Layout from '../Layout';
import { connect } from 'react-redux';
import { getBooks } from '../../actions/books.action';
import SelectNavHOC from '../SelectNavHOC';
import {Route,Switch} from 'react-router-dom';
import Views from '../';

@SelectNavHOC
@connect(mapStateToProps,mapDispatchToProps)
export default class Books extends Component {
	componentDidMount(){
		let {user,BooksList} = this.props;
		BooksList({
			userId:user.id
		});
	}
	render(){
		let {
			isAdmin
		} = this.props;
		
		return (
			<Layout isAdmin={isAdmin}>
				<Switch>
					<Route path="/manage/types" component={Views.Types}/>
					<Route path="/manage/users" component={Views.Users}/>
					<Route path="/manage/books" component={Views.Index}/>
					<Route path="/manage" component={Views.Index}/>
				</Switch>
			</Layout>
		);
	}
}

function mapStateToProps(state) {
	return {
		isAdmin: state.Books.isAdmin,
	}
}
function mapDispatchToProps(dispatch){
	return {
		BooksList: data => dispatch(getBooks(data))
	}
}